<?php

class Core_Backend_Component_Website_View_Block_Index extends Core_Backend_Share_View_Grid {

    public function __construct() {
        parent::__construct();
    }

    protected function buildNavigation($navigation) {
        $navigation->addLabel($this->__('website.title.block_index'));
        parent::buildNavigation($navigation);
    }

    protected function buildToolbar($toolbar) {
        parent::buildToolbar($toolbar);
        $group = $toolbar->createGroup();
        $group->addLink($this->getUrl(array('areaid' => $this->getCurrentAreaId()), 'choose'), $this->__('share.button.create'));
    }

    protected function buildGrid($grid) {
        $this->getTemplate()->assignMulti(array('areas' => $this->getAreas(), 'current_area_id' => $this->getCurrentAreaId()));
        $filter = new Kd_Object($this->getRequest()->getParameter('filter'));
        $grid->setId('block_grid')
                ->setPrimaryKey('id')
                ->setAllowFilter(TRUE)
                ->setSortField($this->getRequest()->getParameter('sort', 'id'))
                ->setSortDirection($this->getRequest()->getParameter('dir', 'asc'))
                ->setSortUrlFormat($this->getSortUrl());
        $grid->addLabelColumn($this->__('share.label.code'), 'code', '{code}')
                ->setSortField('code')
                ->setWidth(200);
        $grid->addLabelColumn($this->__('share.label.name'), 'name', '{name}')
                ->setTextboxFilter(NULL, NULL, $filter->getData('name'))
                ->setSortField('name');
        $grid->addLabelColumn($this->__('share.label.type'), 'module_type', '{module_type}')
                ->setSortField('module_id')
                ->setWidth(100);
        $grid->addLabelColumn($this->__('share.label.enable'), 'enabled', '{enabled}')
                ->setSelectFilter(NULL, NULL, Kd_Localize_Helper::getLanguageItems('status.boolean'), NULL, NULL, $filter->getData('enabled'))
                ->setSortField('enable')
                ->setWidth(60);
        
        $grid->addLinkColumn('#', 'edit', $this->getUrl(array('id' => '{id}'), 'edit'), $this->__('share.button.edit'))
                ->setWidth(40)
                ->setAlign('center');
        $grid->addLinkColumn('#', 'copy', $this->getUrl(array('id' => '{id}'), 'copy'), $this->__('share.button.copy'))
                ->setWidth(40)
                ->setAlign('center');
        $grid->setDataSource($this->getList()->toArray());
        parent::buildGrid($grid);
    }

    protected function buildPagination($pagination) {
        $url = $this->getPaginationUrl();
        $pagination->setUrlFormat($url)->setRecordCount($this->getRecords());
        parent::buildPagination($pagination);
    }

}